<template>
  <div :class="$style.container" class="a_science">
    <h4>
      <p>
        <i :class="$style.icon"/>
        <span>{{title}}</span>
      </p>
      <router-link tag="em" :to="{path:'/more'}">更多</router-link>
    </h4>
    <swiper :options="swiperOption" dir="rtl">
      <swiper-slide v-for="(item, idx) in arr" :key="'science' +idx">
        <ul>
          <li v-for="(sub,index) in item" :key="'science'+idx+'-'+index" @click.stop="handleItemClick(sub)">
            <div :class="$style.left">
              <img v-lazy="sub.poster">
            </div>
            <div :class="$style.right">
              <h4 :class="$style.title">{{sub.original_title}}</h4>
              <p :class="$style.count">{{sub.wish_count}}人想看</p>
              <div :class="$style.desc">
                <div :class="$style.price">
                  <span v-if="sub.price" :class="$style.f1"><small>￥</small><strong>{{sub.price}}</strong></span>
                  <span v-else :class="$style.f2">免费</span>
                </div>
                <p v-if="sub.price" :class="$style.btn">
                  <x-button mini v-if="sub.price && !sub.isMyFilm">购买</x-button>
                  <x-button mini v-else-if="sub.price && sub.isMyFilm">已购买</x-button>
                </p>
              </div>
            </div>
          </li>
        </ul>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
  props: {
    lists: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      swiperOption: {
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        }
      }
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  computed: {
    arr () {
      let arr = [this.lists.slice(0, 3), this.lists.slice(3, 6)]
      return arr
    }
  },
  methods: {
    handleItemClick (item) {
      this.$emit('handleItem', item)
    }
  }
}
</script>

<style lang='less' module>
.container {
  padding: 20px 20px 0px;
  box-sizing: border-box;
  h4 {
    line-height: 0;
    margin-bottom: 10px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    .icon {
      display: inline-block;
      width: 18px;
      height:18px;
      background: url('../../../assets/imgs/index_icon.png') no-repeat;
      background-position-x: center;
      background-size:18px;
      background-position: 0px -36px;
      vertical-align: middle;
    }
    span {
      margin-left:10px;
      font-size:14px;
      font-weight: bold;
      color:#2b333b;
      vertical-align: middle;
    }
    em {
      font-size:14px;
      color:#2b333b;
      vertical-align: middle;
    }
  }
  ul {
    li {
      margin: 10px 0px;
      overflow: hidden;
      .left {
        float: left;
        img {
          width: 108px;
          height:70px;
          object-fit: cover;
          border-radius: 5px;
          border-left: 1px solid #fff;
        }
      }
    .right {
      width: calc(~"100% - 120px");
      padding-left: 12px;
      text-align: left;
      .title {
        color: #2B333B;
        font-size: 15px;
        font-weight: bold;
        line-height: 20px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        // -webkit-box-orient: vertical;
        word-break: break-all;
        word-wrap: break-word;  
      }
      .count {
        margin-top: 8px;
        font-size: 12px;
        color: #71777D;
        line-height: 14px; 
      }
      .desc {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: space-between;
        line-height: 0px;
        align-items: center;
        .price {
          span {
            font-size: 12px;
            line-height: 14px;  
          }
          .f1 {
            color: red;
          }
          .f2 {
            color: #be9e4d;
          }
        }
          .btn {
            button {
              background: red;
              color:#fff;
            }
          }
        }
      }
    }
  }
}

</style>
<style>
  @import 'swiper/dist/css/swiper.css';
</style>
<style scoped>
  .a_science >>> .swiper-container-horizontal > .swiper-pagination-bullets .swiper-pagination-bullet {
    width: 16px;
    display: inline-block;
    border-radius: 5px;
  }
  .a_science >>> .swiper-pagination-bullet-active {
    background:#e36049;
  }
</style>